using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQUEUETABLE1
    {
        public DataRow Convert2QUEUETABLE1(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQUEUETABLE1(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["Q_NAME"] = " ".PadRight(30 ); 
         dwReturn["MSGID"] = " ".PadRight(16 ); 
         dwReturn["CORRID"] = " ".PadRight(128 ); 
         dwReturn["PRIORITY"] = " ".PadRight(0 ); 
         dwReturn["STATE"] = " ".PadRight(0 ); 
         dwReturn["DELAY"] = " ".PadRight(0 ); 
         dwReturn["EXPIRATION"] = " ".PadRight(0 ); 
         dwReturn["TIME_MANAGER_INFO"] = " ".PadRight(0 ); 
         dwReturn["LOCAL_ORDER_NO"] = " ".PadRight(0 ); 
         dwReturn["CHAIN_NO"] = " ".PadRight(0 ); 
         dwReturn["CSCN"] = " ".PadRight(0 ); 
         dwReturn["DSCN"] = " ".PadRight(0 ); 
         dwReturn["ENQ_TIME"] = " ".PadRight(0 ); 
         dwReturn["ENQ_UID"] = " ".PadRight(30 ); 
         dwReturn["ENQ_TID"] = " ".PadRight(30 ); 
         dwReturn["DEQ_TIME"] = " ".PadRight(0 ); 
         dwReturn["DEQ_UID"] = " ".PadRight(30 ); 
         dwReturn["DEQ_TID"] = " ".PadRight(30 ); 
         dwReturn["RETRY_COUNT"] = " ".PadRight(0 ); 
         dwReturn["EXCEPTION_QSCHEMA"] = " ".PadRight(30 ); 
         dwReturn["EXCEPTION_QUEUE"] = " ".PadRight(30 ); 
         dwReturn["STEP_NO"] = " ".PadRight(0 ); 
         dwReturn["RECIPIENT_KEY"] = " ".PadRight(0 ); 
         dwReturn["DEQUEUE_MSGID"] = " ".PadRight(16 ); 
         dwReturn["SENDER_NAME"] = " ".PadRight(30 ); 
         dwReturn["SENDER_ADDRESS"] = " ".PadRight(1024 ); 
         dwReturn["SENDER_PROTOCOL"] = " ".PadRight(0 ); 
         dwReturn["USER_DATA"] = " ".PadRight(0 ); 
         dwReturn["USER_PROP"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQUEUETABLE1(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQUEUETABLE1(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQUEUETABLE1(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQUEUETABLE1(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQUEUETABLE1(dwLocal, ITXDBVERSION);
            }
            UpdateQUEUETABLE1(dwLocal);
        }
        public void InsertQUEUETABLE1(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QUEUETABLE1(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQUEUETABLE1(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QUEUETABLE1 WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QUEUETABLE1  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QUEUETABLE1";
            Return = Result;
            return Return;
        }
        public void DeleteQUEUETABLE1(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QUEUETABLE1   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQUEUETABLE1(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QUEUETABLE1 SET "
                    +"Q_NAME= :Q_NAME,"
                    +"MSGID= :MSGID,"
                    +"CORRID= :CORRID,"
                    +"PRIORITY= :PRIORITY,"
                    +"STATE= :STATE,"
                    +"DELAY= :DELAY,"
                    +"EXPIRATION= :EXPIRATION,"
                    +"TIME_MANAGER_INFO= :TIME_MANAGER_INFO,"
                    +"LOCAL_ORDER_NO= :LOCAL_ORDER_NO,"
                    +"CHAIN_NO= :CHAIN_NO,"
                    +"CSCN= :CSCN,"
                    +"DSCN= :DSCN,"
                    +"ENQ_TIME= :ENQ_TIME,"
                    +"ENQ_UID= :ENQ_UID,"
                    +"ENQ_TID= :ENQ_TID,"
                    +"DEQ_TIME= :DEQ_TIME,"
                    +"DEQ_UID= :DEQ_UID,"
                    +"DEQ_TID= :DEQ_TID,"
                    +"RETRY_COUNT= :RETRY_COUNT,"
                    +"EXCEPTION_QSCHEMA= :EXCEPTION_QSCHEMA,"
                    +"EXCEPTION_QUEUE= :EXCEPTION_QUEUE,"
                    +"STEP_NO= :STEP_NO,"
                    +"RECIPIENT_KEY= :RECIPIENT_KEY,"
                    +"DEQUEUE_MSGID= :DEQUEUE_MSGID,"
                    +"SENDER_NAME= :SENDER_NAME,"
                    +"SENDER_ADDRESS= :SENDER_ADDRESS,"
                    +"SENDER_PROTOCOL= :SENDER_PROTOCOL,"
                    +"USER_DATA= :USER_DATA,"
                    +"USER_PROP= :USER_PROP,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("Q_NAME", OracleType.NVarChar).Value = dwData["Q_NAME"].ToString(); 
          or1.Parameters.Add("MSGID", OracleType.NVarChar).Value = dwData["MSGID"].ToString(); 
          or1.Parameters.Add("CORRID", OracleType.NVarChar).Value = dwData["CORRID"].ToString(); 
          or1.Parameters.Add("PRIORITY", OracleType.NVarChar).Value = dwData["PRIORITY"].ToString(); 
          or1.Parameters.Add("STATE", OracleType.NVarChar).Value = dwData["STATE"].ToString(); 
          or1.Parameters.Add("DELAY", OracleType.NVarChar).Value = dwData["DELAY"].ToString(); 
          or1.Parameters.Add("EXPIRATION", OracleType.NVarChar).Value = dwData["EXPIRATION"].ToString(); 
          or1.Parameters.Add("TIME_MANAGER_INFO", OracleType.NVarChar).Value = dwData["TIME_MANAGER_INFO"].ToString(); 
          or1.Parameters.Add("LOCAL_ORDER_NO", OracleType.NVarChar).Value = dwData["LOCAL_ORDER_NO"].ToString(); 
          or1.Parameters.Add("CHAIN_NO", OracleType.NVarChar).Value = dwData["CHAIN_NO"].ToString(); 
          or1.Parameters.Add("CSCN", OracleType.NVarChar).Value = dwData["CSCN"].ToString(); 
          or1.Parameters.Add("DSCN", OracleType.NVarChar).Value = dwData["DSCN"].ToString(); 
          or1.Parameters.Add("ENQ_TIME", OracleType.NVarChar).Value = dwData["ENQ_TIME"].ToString(); 
          or1.Parameters.Add("ENQ_UID", OracleType.NVarChar).Value = dwData["ENQ_UID"].ToString(); 
          or1.Parameters.Add("ENQ_TID", OracleType.NVarChar).Value = dwData["ENQ_TID"].ToString(); 
          or1.Parameters.Add("DEQ_TIME", OracleType.NVarChar).Value = dwData["DEQ_TIME"].ToString(); 
          or1.Parameters.Add("DEQ_UID", OracleType.NVarChar).Value = dwData["DEQ_UID"].ToString(); 
          or1.Parameters.Add("DEQ_TID", OracleType.NVarChar).Value = dwData["DEQ_TID"].ToString(); 
          or1.Parameters.Add("RETRY_COUNT", OracleType.NVarChar).Value = dwData["RETRY_COUNT"].ToString(); 
          or1.Parameters.Add("EXCEPTION_QSCHEMA", OracleType.NVarChar).Value = dwData["EXCEPTION_QSCHEMA"].ToString(); 
          or1.Parameters.Add("EXCEPTION_QUEUE", OracleType.NVarChar).Value = dwData["EXCEPTION_QUEUE"].ToString(); 
          or1.Parameters.Add("STEP_NO", OracleType.NVarChar).Value = dwData["STEP_NO"].ToString(); 
          or1.Parameters.Add("RECIPIENT_KEY", OracleType.NVarChar).Value = dwData["RECIPIENT_KEY"].ToString(); 
          or1.Parameters.Add("DEQUEUE_MSGID", OracleType.NVarChar).Value = dwData["DEQUEUE_MSGID"].ToString(); 
          or1.Parameters.Add("SENDER_NAME", OracleType.NVarChar).Value = dwData["SENDER_NAME"].ToString(); 
          or1.Parameters.Add("SENDER_ADDRESS", OracleType.NVarChar).Value = dwData["SENDER_ADDRESS"].ToString(); 
          or1.Parameters.Add("SENDER_PROTOCOL", OracleType.NVarChar).Value = dwData["SENDER_PROTOCOL"].ToString(); 
          or1.Parameters.Add("USER_DATA", OracleType.NVarChar).Value = dwData["USER_DATA"].ToString(); 
          or1.Parameters.Add("USER_PROP", OracleType.NVarChar).Value = dwData["USER_PROP"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
